package com.dy.nygl.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dy.nygl.mapper.EquipMonitMapper;
import com.dy.nygl.pojo.EquipMonit;
import com.dy.nygl.service.EquipMonitService;

import javafx.scene.chart.PieChart.Data;

@Service("equipMonitService")
public class EquipMonitServiceImpl implements EquipMonitService {

	@Resource(name = "equipMonitDao")
	private EquipMonitMapper equipMonitDao;

	@Override
	public List<EquipMonit> selectAll() {
		List<EquipMonit> list = equipMonitDao.selectAll();
		return list;
	}

	@Override
	public List<EquipMonit> selectEquip(String sect, String search) {
		if (sect.trim().equals("equipId")) {
			List<EquipMonit> list = equipMonitDao.selectByEquipId(search);
			return list;
		}
		if (sect.trim().equals("equipName")) {
			List<EquipMonit> list = equipMonitDao.selectByEquipName(search);
			return list;
		}
		return null;
	}

	@Override
	public List<EquipMonit> selectByDateLike(String year, String month, String day) {
		String date = "";
		if (!year.trim().equals("") && !month.trim().equals("") && !day.trim().equals("")) {
			date = year.trim() + "-" + month.trim() + "-" + day.trim()+"%";
		}
		if (!year.trim().equals("") && !month.trim().equals("") && day.trim().equals("")) {
			date = year.trim() + "-" + month.trim() + "-" + "%";
		}
		if (!year.trim().equals("") && month.trim().equals("") && day.trim().equals("")) {
			date = year.trim() + "-" + "%";
		}
		if (year.trim().equals("") && month.trim().equals("") && day.trim().equals("")) {
			date = "";
		}

		System.out.println("ServiceImpl===============" + date);
		List<EquipMonit> list = equipMonitDao.selectByDateLike(date.trim());
		return list;
	}

	@Override
	public void update(EquipMonit equipMonit) {
		EquipMonit equipMonit2 = new EquipMonit();
		equipMonit2.setId(equipMonit.getId());
		equipMonit2.setName(equipMonit.getName());
		equipMonit2.setEquipId(equipMonit.getEquipId());
		equipMonit2.setEquipName(equipMonit.getEquipName());
		equipMonit2.setTotalConsum(equipMonit.getTotalConsum());
		equipMonit2.setReferValue(equipMonit.getReferValue());
		equipMonit2.setCurrentConsum(equipMonit.getCurrentConsum());
		equipMonit2.setDate(equipMonit.getDate());
		equipMonitDao.updateByPrimaryKeySelective(equipMonit2);
	}

	@Override
	public void insert(EquipMonit equipMonit) {
		EquipMonit equipMonit2 = new EquipMonit();
	
		equipMonit2.setName(equipMonit.getName());
		equipMonit2.setEquipName(equipMonit.getEquipName());
		equipMonit2.setEquipId(equipMonit.getEquipId());
		equipMonit2.setTotalConsum(equipMonit.getTotalConsum());
		equipMonit2.setReferValue(equipMonit.getReferValue());
		equipMonit2.setCurrentConsum(equipMonit.getCurrentConsum());
		equipMonit2.setDate(equipMonit.getDate());
		equipMonitDao.insert(equipMonit2);
	}

	@Override
	public boolean deleteThis(int id) {
		equipMonitDao.deleteByPrimaryKey(id);
		return true;
	}

}
